#ifndef STATICARRAY_H
#define STATICARRAY_H



template <typename T, int N>
class StaticArray
{
public:
    StaticArray()
    {
        m_array = new T[N];
        if (m_array == nullptr)
        {
            throw "cannot init";
        }
    }
    StaticArray(const StaticArray<T, N> &sa)
    {
        m_array = new T[N];
        for (int i = 0; i < N; i++)
        {
            m_array[i] = sa.m_array[i];
        }
    }
    StaticArray<T, N> &operator=(const StaticArray<T, N> &sa)
    {
        if (this != &sa)
        {
            for (int i = 0; i < N; i++)
            {
                m_array[i] = sa.m_array[i];
            }
        }
        return *this;
    }
    ~StaticArray()
    {
        delete[] m_array;
    }
    int length()
    {
        return N;
    }
    T get(int i)
    {
        return operator[](i);
    }
    void set(int i, T value)
    {
        if (0 <= i && i < N)
        {
            m_array[i] = value;
        }
        else
        {
            throw "out of range";
        }
    }
    T& operator[](int i)
    {
        if (0 <= i && i < N)
        {
            return m_array[i];
        }
        else
        {
            throw "out of range";
        }
    }
    T operator[](int i) const
    {
        if (0 <= i && i < N)
        {
            return m_array[i];
        }
        else
        {
            throw "out of range";
        }
    }
protected:
    T *m_array;
};

#endif // STATICARRAY_H
